package com.teach.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.teach.entity.Config;
import com.teach.entity.user;

public class ConfigDao {

	public static Connection conn = null;
	public static Statement stmt = null;
	public static ResultSet rs = null;
	public static PreparedStatement ptst = null;
	
	 public int  SelectByString() throws SQLException {
		  
		  Config c=new Config();
			try {
				conn = JdbcUtil.getConnection();

				String sql = "select * from sys_config where CONFIG_KEY = 'count'";
				ptst = conn.prepareStatement(sql);
				rs = ptst.executeQuery();
				rs.next();
				c.setCount(rs.getInt("CONFIG_VALUE"));
        }catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			
			JdbcUtil.close(conn, ptst,rs);
			return c.getCount();
		}
			
	 }
	 public 
	 void  UpdateByString(int count) throws SQLException {
		 try {
			 conn = JdbcUtil.getConnection();
				String sql = "update sys_config set CONFIG_VALUE= ? where CONFIG_KEY = 'count'";
				ptst = conn.prepareStatement(sql);
				ptst.setInt(1, count);
				ptst.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			JdbcUtil.close(conn, ptst);
		}
		
	 }
}
